package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.UserYouXiang;

public class YouXiangAdapter extends BaseAdapter {
    private Context context;
    private static UserYouXiang userYouXiang;

    public UserYouXiang getUserYouXiang() {
        return userYouXiang;
    }

    public YouXiangAdapter(Context context) {
        this.context = context;
    }

    public void setUserYouXiang(UserYouXiang userYouXiang) {
        this.userYouXiang = userYouXiang;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (userYouXiang==null){
            return 0;
        }else
        return userYouXiang.getYouXiang().size();
    }

    @Override
    public Object getItem(int i) {
        return userYouXiang.getYouXiang().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.adapter_youxiang, null);
        ViewHolder viewHolder=new ViewHolder(view);
        viewHolder.tvContent.setText(userYouXiang.getYouXiang().get(i).getContent());
        viewHolder.tvHand.setText("【"+userYouXiang.getYouXiang().get(i).getHand()+"】");
        viewHolder.tvTime.setText(userYouXiang.getYouXiang().get(i).getTime());
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvHand;
        public TextView tvContent;
        public TextView tvTime;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvHand = (TextView) rootView.findViewById(R.id.tvHand);
            this.tvContent = (TextView) rootView.findViewById(R.id.tvContent);
            this.tvTime = (TextView) rootView.findViewById(R.id.tvTime);
        }

    }
}
